//
//  DrawEcg.m
//  Ikinloop-demo
//
//  Created by Li Shen on 2021/4/22.
//  Copyright © 2021 lyh. All rights reserved.
//

#import "DrawLiveEcgMgr.h"
#import <QuartzCore/QuartzCore.h>
#import "DrawUtils.h"
#import "DrawGrid.h"
#import "DrawLiveEcg.h"
#import "DrawEcgAnno.h"

@interface DrawLiveEcgMgr()
{
    CGFloat _indicatorX;
    CGFloat _indicatorY;
}
@property (nonatomic, strong) DrawUtils *drawUtils;
@property (nonatomic, strong) DrawGrid *drawGrid;
@property (nonatomic, strong) DrawLiveEcg *drawLeadLiveEcg;
@property (nonatomic, strong) DrawEcgAnno *drawEcgAnno;
@property (nonatomic, strong) CALayer *layer;

@property (nonatomic, strong) NSArray *ecgdatas;
@end

@implementation DrawLiveEcgMgr
- (instancetype)initWithLayer:(CALayer*)layer
{
    self = [super init];
    if (self) {
        self.layer = layer;
        [self setupDefaultValues];
    }
    return self;
}

- (instancetype)initWithLayer:(CALayer*)layer context:(CGContextRef)context{
    self = [super init];
    if (self) {
        self.layer = layer;
        self.context = context;
        [self setupDefaultValues];
    }
    return self;
}

- (void)setupDefaultValues{
    self.drawUtils = [[DrawUtils alloc] initWithLayer:self.layer];
    self.drawGrid = [[DrawGrid alloc] initWithLayer:self.layer];
    self.drawLeadLiveEcg = [[DrawLiveEcg alloc] initWithLayer:self.layer];
    self.drawEcgAnno = [[DrawEcgAnno alloc] initWithLayer:self.layer];
    self.smallgridColor = [UIColor greenColor];
    self.bgColor = [UIColor blackColor];
    self.gridColor = [UIColor greenColor];
    self.ecgColor = [UIColor greenColor];
}

- (void)reset{
    [self.drawLeadLiveEcg reset];
}

- (void)reload{
    [self.drawGrid reload];
    [self.drawEcgAnno reload];
}

- (void)setSmallgridColor:(UIColor *)smallgridColor{
    _smallgridColor = smallgridColor;
    self.drawGrid.smallgridColor = _smallgridColor;
}

- (void)setBgColor:(UIColor *)bgColor{
    _bgColor = bgColor;
    self.drawGrid.bgColor = _bgColor;
}

- (void)setGridColor:(UIColor *)gridColor{
    _gridColor = gridColor;
    self.drawGrid.gridColor = gridColor;
}

- (void)setEcgColor:(UIColor *)ecgColor{
    _ecgColor = ecgColor;
    self.drawLeadLiveEcg.ecgColor = ecgColor;
    self.drawEcgAnno.ecgColor = ecgColor;
}

- (void)setEcgLineWidth:(CGFloat)ecgLineWidth{
    _ecgLineWidth = ecgLineWidth;
    self.drawLeadLiveEcg.lineWidth = ecgLineWidth;
}

- (void)setSmallGridLineWidth:(CGFloat)smallGridLineWidth{
    _smallGridLineWidth = smallGridLineWidth;
    self.drawGrid.smallGridLineWidth = smallGridLineWidth;
}

- (void)setGridLineWidth:(CGFloat)gridLineWidth{
    _gridLineWidth = gridLineWidth;
    self.drawGrid.gridLineWidth = gridLineWidth;
}

- (void)drawBackgroundGrid{
    [self.drawGrid drawBackgroundGrid];
}

- (void)setContext:(CGContextRef)context{
    _context = context;
}

- (void)drawLineEcg:(NSArray*)ecgdatas ecgStates:(NSArray *)ecgstates{
    self.ecgdatas = ecgdatas;
    [self.drawEcgAnno drawLineEcg:ecgdatas ecgStates:ecgstates];
}

- (void)drawWaveByRepeat:(int)ecgdata{
//    [self.drawGrid drawBackgroundGridWithContext];
    [self.drawLeadLiveEcg drawWaveByRepeat:ecgdata];
}

- (CGFloat)getxStepPixelPerPoint{
    return [self.drawEcgAnno getxStepPixelPerPoint];
}

- (int)getPointMaxNumPerScreen{
    return [self.drawEcgAnno getPointMaxNumPerScreen];
}

- (void)getEcgStateByXY:(CGPoint)point{
    [self.drawEcgAnno getEcgStateByXY:point];
}
@end
